<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p id="time">2021-3-9 16:50:00</p>
    <script>
        var endTime = "2021-3-9 11:30:00";
        var p = document.getElementById("time");
        function showTime(endTime){
            endTime = new Date(endTime).getTime();
            var nowTime = new Date().getTime();
            var gapTime = endTime - nowTime;
            var allSeconds = Math.floor(gapTime/1000);
            var hours = Math.floor(allSeconds/3600);
            // console.log(deal(hours));
            var minutes = Math.floor(allSeconds%3600/60);
            var seconds = Math.floor(allSeconds%60);
            var countdown = deal(hours)+":"+deal(minutes)+":"+deal(seconds);
            // console.log(countdown);
            return countdown;
        }
        function deal(num){
            if(num<10){
                num = "0"+num;
            }
            return num+""
        }
        setInterval(function(){
            p.innerHTML = showTime(endTime);
        },1000)
    </script>
</body>
</html>